﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class MsgBoardMan : xIx.Web.UI.PageBase
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void LSA_OnLoadingData(object sender, xIx.Web.Portal.SEDataEventArg e)
    {
        using (xIx.Data.DbHelper dh=new xIx.Data.DbHelper())
        {
            DataTable dt= dh.Table["Sys_QABoard"].Fields("*"," FixStr(QText,32,'…') QTextEx ").OrderBy("QDate Desc").Select();
            e.OutDataView= dt.DefaultView;
        }
    }

    protected void LSA_OnOnDeletingData(object sender, xIx.Web.Portal.SEDataEventArg e)
    {
        using (xIx.Data.DbHelper dh=new xIx.Data.DbHelper())
        {
            DataTable dt = dh.Table["Sys_QABoard"].PK("ID", e.InKeys["ID"]).Select();
            if (dt.Rows.Count > 0)
            {

                string ea= dt.Rows[0]["ExtA"].ToString();

                if (!string.IsNullOrEmpty(ea))
                {
                    try
                    {
                        System.IO.File.Delete(Server.MapPath(ea));
                        System.IO.File.Delete(Server.MapPath(ea + ".fileinfo"));
                    }
                    catch { }
                }
                e.OutEffectRows = dh.Table["Sys_QABoard"].PK("ID", e.InKeys["ID"]).Delete();
            }
        }
    }
    
    //protected void Delete(object sender, CommandEventArgs e)
    //{

    //}
    //protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    //{
    //    if (e.CommandName == "Del") {
    //        using (xIx.Data.DbHelper dh = new xIx.Data.DbHelper())
    //        {
    //            int r = dh.Table["Sys_QABoard"].PK("ID", e.CommandArgument.ToString()).Delete();
    //            if (r == 1) Alert("操作完成。");
    //            else Alert("操作失败。");
    //            GridView1.DataBind();
    //        }
    //    }
    //}
    protected void Button1_Click(object sender, EventArgs e)
    {
        GridView1.DataBind();
    }

    protected void Button2_Click(object sender, EventArgs e)
    {
        DataTable dt =null;
        using (xIx.Data.DbHelper dh = new xIx.Data.DbHelper())
        {
            dt= dh.Table["Sys_QABoard"].Fields("QType 评论类别,Title 标题,QUserTitle 评论人,QDate 日期,QText 内容,RText 备注").OrderBy("QDate Desc").Select();
        }

        string s = string.Empty;

        foreach (DataColumn dc in dt.Columns)
        {
            s += dc.ColumnName + ",";
        }
        s += "\r\n";

        foreach (DataRow dr in dt.Rows)
        {
            foreach (DataColumn dc in dt.Columns)
            {
                s += dr[dc].ToString().Replace(',','，') + ",";
            }
            s += "\r\n";
        }
        Response.Clear();
        Response.ContentType = "application/ms-excel";
        Response.ContentEncoding = System.Text.Encoding.Default;
        Response.AddHeader("content-disposition", "attachment; filename=Data.csv");
        Response.Write(s);
        Response.Flush();
        Response.End();
        //GridView1.DataBind();
    }
}
